package com.dcw.lixb.designmode.prototype;

import java.util.Hashtable;

/**
 * @author lixiaobin
 * @date 2020-07-17 11:00:51
 * @desc 描述信息
 */
public class ShapeCache {
    private static Hashtable<String, Shape> cacheShape = new Hashtable<>();

    public static Shape getShape(String type) {
        Shape shape = cacheShape.get(type);
        return (Shape) shape.clone();
    }

    public static void loadCache() {
        Circle circle = new Circle();
        circle.setId("1");
        cacheShape.put(circle.getId(), circle);

        Square square = new Square();
        square.setId("2");
        cacheShape.put(square.getId(), square);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("3");
        cacheShape.put(rectangle.getId(), rectangle);
    }
}
